/* Copyright (c) 2010, Peter Lényi */
/* Licensed under The BSD License. */

package gem.apps.gfs2.engine.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class FileMeta encapsulates file's metadata.
 * 
 * @author Peter Lényi
 * @version 20100515F
 */
@Entity
public class FileMeta implements Serializable
{
    /**
     * uid
     * name
     * mime
     * size
     * owner
     * uploaded
     */

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long    uid;
    private String  name;
    private String  mime;
    @Column(name="FILESIZE")
    private Long    size;
    @ManyToOne(cascade={CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE},optional=false)
    private Person  owner;
    @Temporal(TemporalType.TIMESTAMP)
    private Date    uploaded;

    public FileMeta() {}

    public String getMime() {
        return mime;
    }

    public void setMime(String mime) {
        this.mime = mime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person getOwner() {
        return owner;
    }

    public void setOwner(Person owner) {
        this.owner = owner;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Date getUploaded() {
        return uploaded;
    }

    public void setUploaded(Date uploaded) {
        this.uploaded = uploaded;
    }

    @Override
    public boolean equals(Object o) {
        boolean equal = false;
        if (o != null && o instanceof FileMeta) {
            FileMeta fm = (FileMeta) o;
            if (uid == fm.uid) {
                equal = true;
            }
        }
        return equal;
    }

    @Override
    public int hashCode() {
        return uid.hashCode();
    }

    @Override
    public String toString() {
        return "GFS2:FileMeta#" + uid;
    }
}
